home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / BevelImageAPIWindow.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  6.0 KB  |  276 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        BevelImageAPIWindow.cp
  3.  
  4.     Contains:    Bevel Button content type examples.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. //
  28. //    This file implements a dialog demonstrating the different
  29. //    methods of setting bevel button content types, such as pictures,
  30. //    icons, and text.
  31. //
  32.  
  33. #include "AppearanceSamplePrefix.h"
  34.  
  35. #include <Folders.h>
  36. #include <Appearance.h>
  37. #include "BevelImageAPIWindow.h"
  38. #include "AppearanceHelpers.h"
  39.  
  40. void    HandleBevelDialog( DialogPtr dialog, short itemHit );
  41.  
  42. void    EnableDisableAll( DialogPtr dialog, Boolean enable );
  43. void    SetControlValues( DialogPtr dialog, short value );
  44. void    SetUpBevelDialog( DialogPtr dialog );
  45.  
  46. #define DIRECT        1
  47.  
  48. enum {
  49.     kBevelButton        = 1,
  50.     kImageWell            = 2,
  51.  
  52.     kBBIconSuite        = 4,
  53.     kBBColorIcon        = 5,
  54.     kBBPicture            = 6,
  55.     kBBTextOnly         = 7,
  56.  
  57.     kIWIconSuite        = 8,
  58.     kIWColorIcon        = 9,
  59.     kIWPicture            = 10,
  60.     
  61.     kIWIconSuiteHandle    = 11,
  62.     kIWColorIconHandle    = 12,
  63.     kIWPictureHandle    = 13,
  64.     
  65.     kBBIconSuiteHandle    = 14,
  66.     kBBColorIconHandle    = 15,
  67.     kBBPictureHandle    = 16
  68. };
  69.  
  70. BevelImageAPIWindow::BevelImageAPIWindow() : BaseDialog( 1002 )
  71. {
  72.     if ( fWindow )
  73.     {
  74.         ShowWindow( fWindow );
  75.         
  76.         GetIconSuite( &fIconSuite, 128, svAllAvailableData );
  77.         fColorIcon = GetCIcon( 128 );
  78.         
  79.         OSErr err = GetIconRef( kOnSystemDisk, kSystemIconsCreator, kClippingPictureTypeIcon, &fIconRef );
  80.         if ( err ) fIconRef = nil;
  81.     }
  82. }
  83.  
  84. BevelImageAPIWindow::~BevelImageAPIWindow()
  85. {
  86.     if ( fWindow )
  87.     {
  88.         if ( fIconSuite )
  89.             DisposeIconSuite( fIconSuite, true );
  90.         
  91.         if ( fColorIcon )
  92.             DisposeCIcon( fColorIcon );
  93.  
  94.         if ( fIconRef )
  95.             ReleaseIconRef( fIconRef );
  96.     }
  97. }
  98.  
  99. void
  100. BevelImageAPIWindow::HandleItemHit( short itemHit )
  101. {
  102.     ControlHandle                control;
  103.     ControlButtonContentInfo    info;
  104.     OSErr                        err;
  105.     
  106.     switch ( itemHit ) {
  107.         case kBBIconSuite:
  108.             GetDialogItemAsControl( fDialog, kBevelButton, &control );
  109.             
  110.             info.contentType = kControlContentIconSuiteRes;
  111.             info.u.resID = 128;
  112.             err = SetBevelButtonContentInfo( control, &info );
  113.             
  114.             SetControlTitle( control, "\p" );
  115.             
  116.             if ( err == noErr )
  117.                 DrawOneControl( control );
  118.                 
  119.             break;
  120.         
  121.         case kBBColorIcon:
  122.             GetDialogItemAsControl( fDialog, kBevelButton, &control );
  123.             
  124.             info.contentType = kControlContentCIconRes;
  125.             info.u.resID = 128;
  126.             err = SetBevelButtonContentInfo( control, &info );
  127.             
  128.             SetControlTitle( control, "\p" );
  129.  
  130.             if ( err == noErr )
  131.                 DrawOneControl( control );
  132.                 
  133.             break;
  134.         
  135.         case kBBPicture:
  136.             GetDialogItemAsControl( fDialog, kBevelButton, &control );
  137.             
  138.             info.contentType = kControlContentPictRes;
  139.             info.u.resID = 129;
  140.             err = SetBevelButtonContentInfo( control, &info );
  141.             
  142.             SetControlTitle( control, "\p" );
  143.  
  144.             if ( err == noErr )
  145.                 DrawOneControl( control );
  146.                 
  147.             break;
  148.         
  149.         case kBBTextOnly:
  150.             GetDialogItemAsControl( fDialog, kBevelButton, &control );
  151.             
  152.             info.contentType = kControlContentTextOnly;
  153.             info.u.resID = 0;
  154.             err = SetBevelButtonContentInfo( control, &info );
  155.             
  156.             SetControlTitle( control, "\pTesting" );
  157.                             
  158.             break;
  159.             
  160.  
  161.         case kBBIconSuiteHandle:
  162.             GetDialogItemAsControl( fDialog, kBevelButton, &control );
  163.             
  164.             info.contentType = kControlContentIconSuiteHandle;
  165.             info.u.iconSuite = fIconSuite;
  166.             err = SetBevelButtonContentInfo( control, &info );
  167.             
  168.             if ( err == noErr )
  169.                 DrawOneControl( control );
  170.                 
  171.             break;
  172.         
  173.         case kBBColorIconHandle:
  174.             GetDialogItemAsControl( fDialog, kBevelButton, &control );
  175.             
  176. #if 0
  177.             info.contentType = kControlContentCIconHandle;
  178.             info.u.cIconHandle = fColorIcon;
  179. #else
  180.             if ( fIconRef )
  181.             {
  182.                 info.contentType = kControlContentIconRef;
  183.                 info.u.iconRef = fIconRef;
  184.             }
  185. #endif
  186.             err = SetBevelButtonContentInfo( control, &info );
  187.             
  188.             if ( err == noErr )
  189.                 DrawOneControl( control );
  190.                 
  191.             break;
  192.         
  193.         case kBBPictureHandle:
  194.             GetDialogItemAsControl( fDialog, kBevelButton, &control );
  195.             
  196.             info.contentType = kControlContentPictHandle;
  197.             info.u.picture = GetPicture( 129 );
  198.             err = SetBevelButtonContentInfo( control, &info );
  199.             
  200.             if ( err == noErr )
  201.                 DrawOneControl( control );
  202.                 
  203.         case kIWIconSuite:
  204.             GetDialogItemAsControl( fDialog, kImageWell, &control );
  205.             
  206.             info.contentType = kControlContentIconSuiteRes;
  207.             info.u.resID = 128;
  208.             err = SetBevelButtonContentInfo( control, &info );
  209.             
  210.             if ( err == noErr )
  211.                 DrawOneControl( control );
  212.                 
  213.             break;
  214.         
  215.         case kIWColorIcon:
  216.             GetDialogItemAsControl( fDialog, kImageWell, &control );
  217.             
  218.             info.contentType = kControlContentCIconRes;
  219.             info.u.resID = 128;
  220.             err = SetBevelButtonContentInfo( control, &info );
  221.             
  222.             if ( err == noErr )
  223.                 DrawOneControl( control );
  224.                 
  225.             break;
  226.         
  227.         case kIWPicture:
  228.             GetDialogItemAsControl( fDialog, kImageWell, &control );
  229.             
  230.             info.contentType = kControlContentPictRes;
  231.             info.u.resID = 129;
  232.             err = SetBevelButtonContentInfo( control, &info );
  233.             
  234.             if ( err == noErr )
  235.                 DrawOneControl( control );
  236.                 
  237.             break;            
  238.  
  239.         case kIWIconSuiteHandle:
  240.             GetDialogItemAsControl( fDialog, kImageWell, &control );
  241.             
  242.             info.contentType = kControlContentIconSuiteHandle;
  243.             info.u.iconSuite = fIconSuite;
  244.             err = SetBevelButtonContentInfo( control, &info );
  245.             
  246.             if ( err == noErr )
  247.                 DrawOneControl( control );
  248.                 
  249.             break;
  250.         
  251.         case kIWColorIconHandle:
  252.             GetDialogItemAsControl( fDialog, kImageWell, &control );
  253.             
  254.             info.contentType = kControlContentCIconHandle;
  255.             info.u.cIconHandle = fColorIcon;
  256.             err = SetBevelButtonContentInfo( control, &info );
  257.             
  258.             if ( err == noErr )
  259.                 DrawOneControl( control );
  260.                 
  261.             break;
  262.         
  263.         case kIWPictureHandle:
  264.             GetDialogItemAsControl( fDialog, kImageWell, &control );
  265.             
  266.             info.contentType = kControlContentPictHandle;
  267.             info.u.picture = GetPicture( 129 );
  268.             err = SetBevelButtonContentInfo( control, &info );
  269.             
  270.             if ( err == noErr )
  271.                 DrawOneControl( control );
  272.                 
  273.             break;            
  274.     }
  275. }
  276.